<?php

namespace server\dao;

use common\helpers\ConstantHelper;
use Yii;

/**
 * This is the model class for table "equ_lane".
 *
 * @property int $id
 * @property int $station_id 站点ID
 * @property string $name 名称
 * @property int $status 0:禁用，1:启用，-1:删除
 * @property int $created_at 创建时间
 * @property int $updated_at 更新时间
 */
class EquLane extends \common\core\server\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'equ_lane';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['station_id'], 'required'],
            [['station_id', 'status', 'created_at', 'updated_at'], 'integer'],
            [['name'], 'string', 'max' => 60],
            [['status'], 'default', 'value' => 1],

        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'station_id' => 'Station ID',
            'name' => 'Name',
            'status' => 'Status',
            'created_at' => 'Created At',
            'updated_at' => 'Updated At',
        ];
    }

    public function getLaneList($params = [], $isAll = true)
    {
        $query = $this->find();
        $query->from($this->tableName());
        $query->select('id,name,status,station_id,created_at,updated_at');
        if ($this->issetAndEmpty($params, 'station_id')) {
            $query->andWhere(['station_id' => $params['station_id']]);
        }
        $query->andWhere(['status' => ConstantHelper::NOT_DELETE]);
        // return $query->createCommand()->getRawSql();
        return $isAll ? $query->asArray()->all() : $this->page($query);
    }

    public function getLaneByName($name){
        return  self::findOne(['name'=>$name,'status' => ConstantHelper::NOT_DELETE]);
    }
}
